package com.ruoyi.wechat.api;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.wechat.domain.Banner;
import com.ruoyi.wechat.domain.FacilityType;
import com.ruoyi.wechat.domain.WxCampFacilityVo;
import com.ruoyi.wechat.service.IFacilityService;
import com.ruoyi.wechat.service.IWxFacilityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping("/wechat/facility")
public class WxFacilityController extends BaseController {
    @Autowired
    private IWxFacilityService iWxFacilityService;
    @GetMapping("/wxlist")
    public AjaxResult wxlist()
    {

        List<FacilityType> facilityTypes=iWxFacilityService.getFacilityTypeAndFacility();
        return success(facilityTypes);
    }
    /**
     * 根据营地Id和服务设置Id集合完成批量添加
     */
    @PostMapping("/wxadd")
    public AjaxResult add(@RequestBody WxCampFacilityVo CampFacilityVo)
    {
      int result=  iWxFacilityService.add(CampFacilityVo.getCampId(),CampFacilityVo.getFacilityIds());
        return success(result);
    }
//
//        if(wxCampFacilityVo.getCampId()==null){
//            return error("营地Id不能为空");
//        }
//        if(wxCampFacilityVo.getFacilityIds()==null){
//            return error("服务设施Id不能为空");
//        }
//
//        return toAjax(iWxFacilityService.insertCampFacility(CampFacilityVo.getCampId(),
//           CampFacilityVo.getFacilityIds());
//
//    }

    /**
     * 根据营地Id查询该营地的服务设施列表
     * @param campId
     * @return
     */
    @GetMapping("/wxgetInfo/{campId}")
    public  AjaxResult getInfo(@PathVariable("campId") String campId){
        if(campId == null){
            return  error("营地Id不能为空");
        }
        List<FacilityType> list=iWxFacilityService.campFacilityListCampId(campId);
        return  success(list);
    }
    /**
     * 根据营地Id完成删除
     * @param campId
     * @return
     */
    @GetMapping("/wxdelete/{campId}")
    public  AjaxResult delete(@PathVariable("campId") String campId){
        if(campId == null){
            return  error("营地Id不能为空");
        }
        return toAjax(iWxFacilityService.deleteCampFacilityByCampId(campId));

    }


}
